<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标段编号">
              <a-input placeholder="请输入标段编号" v-model="queryParam.bidSectionCode"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="问题状态">
              <j-dict-select-tag
                placeholder="请选择问题状态"
                v-model="queryParam.queStatus"
                dictCode="questioning_status"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleAnswer(record)" :disabled="record.queStatus == 2">答复</a>
        </span>
      </a-table>
    </div>
    <a-modal
      title="问题答复"
      :visible="answerVisible"
      :confirmLoading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      :destroyOnClose="true"
      cancelText="关闭"
    >
      <a-form-item label="问题描述">
        {{ selectRow.queContent }}
      </a-form-item>
      <a-textarea v-model="answerContent" rows="4" placeholder="请输入答复内容 " />
    </a-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'ExOnlineQuestioningList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  props: { projectId: {} },
  data() {
    return {
      description: '问题质询管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '标段名称',
          align: 'center',
          dataIndex: 'bidSectionName',
        },
        {
          title: '问题类型',
          align: 'center',
          dataIndex: 'queType_dictText',
        },
        {
          title: '问题描述',
          align: 'center',
          dataIndex: 'queContent',
        },
        {
          title: '提问时间',
          align: 'center',
          dataIndex: 'queDate',
        },
        {
          title: '提问人',
          align: 'center',
          dataIndex: 'queName',
        },
        {
          title: '问题状态',
          align: 'center',
          dataIndex: 'queStatus_dictText',
        },
        {
          title: '问题回复',
          align: 'center',
          dataIndex: 'answer',
        },
        {
          title: '附件',
          align: 'center',
          dataIndex: 'attachmentCode',
          scopedSlots: { customRender: 'fileSlot' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exOnlineQuestioning/exOnlineQuestioning/list',
        delete: '/exOnlineQuestioning/exOnlineQuestioning/delete',
        deleteBatch: '/exOnlineQuestioning/exOnlineQuestioning/deleteBatch',
        exportXlsUrl: '/exOnlineQuestioning/exOnlineQuestioning/exportXls',
        importExcelUrl: 'exOnlineQuestioning/exOnlineQuestioning/importExcel',
        edit: '/exOnlineQuestioning/exOnlineQuestioning/edit',
      },
      dictOptions: {},
      superFieldList: [],
      answerVisible: false,
      selectRow: { queContent: '' },
      answerContent: '', //答复内容
      confirmLoading: false,
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'projectId', text: '项目id', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'bidSectionCode',
        text: '标段（包）编号 - 电子招标投标系统技术规范 第1部分：交易平台技术规范的附录b.3.5标段（包）编号',
        dictCode: '',
      })
      fieldList.push({ type: 'string', value: 'queType', text: '问题类型', dictCode: 'questioning_type' })
      fieldList.push({ type: 'string', value: 'queContent', text: '问题描述 - 自由文本', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'queDate', text: '提问时间 - 日期时间型，格式为yyyymmddhhmmss' })
      fieldList.push({ type: 'string', value: 'queName', text: '提问人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'unitName', text: '提问人所在单位', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'queStatus',
        text: '问题状态 - 参考b.9.18问题状态',
        dictCode: 'questioning_status',
      })
      fieldList.push({ type: 'string', value: 'answer', text: '问题回复 - 自由文本', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attachmentCode', text: '附件关联标识号', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleAnswer(record) {
      this.answerContent = ''
      this.selectRow = record
      this.answerVisible = true
    },
    handleCancel() {
      this.answerVisible = false
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      console.log('this.projectId', this.projectId)
      if (!this.projectId) {
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      params['projectId'] = this.projectId
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleOk() {
      var that = this
      that.confirmLoading = true
      var param = Object.assign({}, this.selectRow)
      param.answer = that.answerContent
      param.queStatus = 2 //已回复
      httpAction(this.url.edit, param, 'put')
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.answerVisible = false
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>